package com.zzw.junit5demo;

import com.zzw.junit5demo.extension.InterceptorExtension;
import com.zzw.junit5demo.extension.MyTestTemplateInvocationContextProvider;
import com.zzw.junit5demo.extension.Random;
import com.zzw.junit5demo.extension.RandomNumberExtension;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import java.util.Arrays;
import java.util.List;

/**
 * @author zzw
 * @version 1.0
 * @title InterceptorDemo
 * @description <拦截器扩展>
 * @datetime 2023-06-16 23:16
 */
@ExtendWith({InterceptorExtension.class,
        RandomNumberExtension.class,
        })
public class InterceptorDemo {

    @ParameterizedTest
    @ValueSource(ints = { 1, 2, 3 })
    void testInterceptor(int randomNumber){
        System.out.println("=======>>>>" + randomNumber);
    }

    @Test
    void testInterceptorRandom(@Random int randomNumber){
        System.out.println("==============");
        System.out.println("=======>>>>" + randomNumber);
        // int a = randomNumber/0;
    }

    final List<String> fruits = Arrays.asList("apple", "banana", "lemon");

    @ExtendWith(MyTestTemplateInvocationContextProvider.class)
    @TestTemplate
    void testMyProvider(String fruit){
        System.out.println("=======>>>>" + fruit);
        Assertions.assertTrue(fruits.contains(fruit));
    }

}
